package com.plum.admin.common.strategy.data;

import com.google.common.collect.Lists;
import com.plum.admin.common.enums.DataScopeTypeEnum;
import com.plum.admin.modules.sys.dto.RoleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * TODO
 *
 * @author 子丶沫
 * @version 1.0
 * @date 2021/9/1 16:44
 */
@Component
public class DataScopeContext {
    @Autowired
    private final Map<String,AbstractDataScopeHandler> strategyMap=new ConcurrentHashMap<>(16);

    public DataScopeContext(Map<String, AbstractDataScopeHandler> strategy){
        strategy.forEach(this.strategyMap::put);
    }

    public List<String> getDeptIdListForDataScope(RoleDTO roleDTO,Integer type){
        return strategyMap.get(String.valueOf(type)).getDeptIdList(roleDTO, DataScopeTypeEnum.valueOf(type));
    }
}
